package com.panghu.controller;


import com.panghu.entity.ApiResult;
import com.panghu.entity.Replay;
import com.panghu.service.ReplayService;
import com.panghu.service.impl.ReplayServiceImpl;
import com.panghu.utils.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 回复表 前端控制器
 * </p>
 *
 * @author huahua
 * @since 2022-03-19
 */
@RestController
public class ReplayController {

    @Autowired
    private ReplayService replayService;

    @PostMapping("/replay")
    public ApiResult add(@RequestBody Replay replay) {
        boolean save = replayService.save(replay);
        if (save) {
            return ApiResultHandler.buildApiResult(200,"添加成功！",save);
        } else {
            return ApiResultHandler.buildApiResult(400,"添加失败！",null);
        }
    }

    @GetMapping("/replay/{messageId}")
    public ApiResult findAllById(@PathVariable("messageId") Integer messageId) {
        //按照主评论id进行查询
        Map<String,Object> map = new HashMap<>();
        map.put("messageId",messageId);
        List<Replay> res = replayService.listByMap(map);
        return ApiResultHandler.buildApiResult(200,"根据messageId查询",res);
    }

}

